import './tree_node_data.dart';
import 'package:flutter/material.dart';

import 'tree_node.dart';

class TreeView extends StatelessWidget {
  final List<TreeNodeData> lstData;


  final double offsetLeft;

  final Function titleOnTap;
  final Function leadingOnTap;
  final Function trailingOnTap;

  const TreeView(this.lstData,{
    this.offsetLeft = 24.0,
    this.titleOnTap,
    this.leadingOnTap,
    this.trailingOnTap,
  }) : assert(lstData != null);

  List<TreeNode> _geneTreeNodes(List list) {
    List treeNodes = <TreeNode>[];

    for (int i = 0; i < list.length; i++) {
      final TreeNodeData item = list[i];
      final title = item.title == null ? null : Text(item.title);
      final leading = item.leading == null ? null : Text(item.leading);
      final expaned = item.expaned == null ?? false;
      final children = item.children as List;

      treeNodes.add(TreeNode(
        item,
        title: title,
        leading: leading,
        titleOnTap: titleOnTap,
        leadingOnTap: leadingOnTap,
        trailingOnTap: trailingOnTap,
      ));
    }

    return treeNodes;
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: List.generate(lstData.length, (int index) {
        final TreeNodeData item = lstData[index];
        final title = item.title == null ? null : Text(item.title);
        final leading =
            item.leading== null ? null : Text(item.leading);
        final expaned = item.expaned ?? false;
        final children = item.children as List;

        return TreeNode(
          item,
          leading: leading,
          titleOnTap: titleOnTap,
          leadingOnTap: leadingOnTap,
          trailingOnTap: trailingOnTap,
        );
      }),
    );
  }
}
